package com.gacu.viewer.client.algo.match;

import com.gacu.viewer.client.algo.AbsAlgorithm;
import com.gacu.viewer.client.algo.WrapperRNA;
import com.gacu.viewer.client.rna.Nucleotide;
import com.gacu.viewer.client.rna.RNAss;

public class MatchAlgorithm extends AbsAlgorithm {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public MatchAlgorithm()
	{
		super();
	}

	public MatchAlgorithm(RNAss[] strands, RNAss[] structs) {
		super(strands, structs);
	}

    //TODO : match !?
    @Override
    public void execute() {    	
    	structsResult = new WrapperRNA[1];
    	structsResult[0] = null;
		int match = 0;
	
		if (structs != null && structs.length == 1){
			structsResult[0] = new WrapperRNA();
	    	structsResult[0].rna = structs[0];
			for (Nucleotide n : structsResult[0].rna){
			    if (n.m_linked_previus){
					switch(n.m_linked.m_ribose){
						case 'G':
						    if (n.m_ribose != 'C') {
						    	n.m_ribose = ' ';
						    }
						    break;
						case 'A':
						    if (n.m_ribose != 'U') {
						    	n.m_ribose = ' ';
						    }
						    break;
						case 'C':
						    if (n.m_ribose != 'G') {
						    	n.m_ribose = ' ';
						    }
						    break;
						case 'U':
						    if (n.m_ribose != 'A') {
						    	n.m_ribose = ' ';
						    }
						    break;
					}
			    }
			    if (n.m_ribose != ' ') {
				    match++;
				}
			}	
			structsResult[0].match = (double)match;
		}
    }
}
